<?php

//父类用self调用某属性（smarty）..子类继承父类..当子类运行父类继承的方法时（$this->display()），该静态变量怎么运行的
class IndexControl extends CommonControl {

        public function index() {
                if (!$this->is_cached()) {
                        $this->assign_head();
//查询一级和二级分类，并将二级分类压入到一级分类的某个子项中
                        $data = M('category')->query('SELECT * FROM hd_category where pid=0');
                        foreach ($data as $k => $v) {
                                $sonData = M('category')->query('SELECT * FROM hd_category where pid=' . $v['cid']);
                                $data[$k]['son'] = $sonData;
                        }
                        $this->assign('data', $data);
//待解决问题
                        $unsolve = M('category')->query('SELECT * FROM hd_ask where solve=0 order by asid desc  limit 5');
                        $this->assign('unsolve', $unsolve);
//高分悬赏问题
                        $higeGrade = M('category')->query('SELECT * FROM hd_ask where reward>=20 and solve=0 order by reward desc ');
                        $this->assign('higeGrade', $higeGrade);
                }
                $this->display();
        }

        public function search() {
                if (IS_POST) {
                        $cate = M('category')->query('SELECT * FROM hd_category');
                        $searchCon = trim(adds_html($_POST['searchCon']));
                        $sql = "SELECT  *, a.content as askcontent,a.asid,an.content as anscontent,a.time FROM hd_ask as a left join hd_answer as an on an.asid=a.asid  join  hd_category as c on c.cid=a.cid where   a.content like '%{$searchCon}%'";
                        $data = M('category')->query($sql);
                        foreach ($data as $k => $v) {
//把详细分类增加到搜索结果中
                                $data[$k]['cateinfo'] = $this->father_cate($cate, $v['cid']);
                                $data[$k]['cateinfo'] = array_reverse($data[$k]['cateinfo']);
                        }
//倒序
                        $this->assign('searchinfo', $data);
                }
                $this->display();
        }

}

?>